import * as echarts from "echarts";
import { useEffect, useRef } from "react";

const BarChart = ({ title }) => {
  const chartRef = useRef();
  useEffect(() => {
    // 获取 DOM 元素
    const chartDom = chartRef.current;
    // 初始化 ECharts 实例
    const myChart = echarts.init(chartDom);
    // 指定图表的配置项和数据
    const option = {
      title: {
        text: title,
      },
      xAxis: {
        type: "category",
        data: ["Vue", "React", "Angular"],
      },
      yAxis: {
        type: "value",
      },
      series: [
        {
          data: [20, 50, 70],
          type: "bar",
        },
      ],
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
  }, [title]);
  return (
    <>
      <div ref={chartRef} style={{ width: "600px", height: "400px" }}></div>
    </>
  );
};

export default BarChart;
